this.BX=this.BX||{};(function(e,t,r,o,i,a,l,n,s,d,f){"use strict";function c(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);if(t)o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}));r.push.apply(r,o)}return r}function u(e){for(var t=1;t<arguments.length;t++){var r=arguments[t]!=null?arguments[t]:{};if(t%2){c(Object(r),true).forEach((function(t){babelHelpers.defineProperty(e,t,r[t])}))}else if(Object.getOwnPropertyDescriptors){Object.defineProperties(e,Object.getOwnPropertyDescriptors(r))}else{c(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}}return e}var g=new Map;g.set("business-light",{theme:"business-light",dark:false,style:"",color:{primary:"#0f58d0ff",primaryText:"#ffffffff",background:"#ffffffff",text:"#000000ff",fieldBackground:"#00000011",fieldFocusBackground:"#ffffffff",fieldBorder:"#00000016"},shadow:true,font:{uri:"",family:""},border:{left:false,top:false,bottom:true,right:false}});g.set("business-dark",{theme:"business-dark",dark:true,style:"",color:{primary:"#0f58d0ff",primaryText:"#ffffffff",background:"#282d30ff",text:"#ffffffff",fieldBackground:"#ffffff11",fieldFocusBackground:"#00000028",fieldBorder:"#ffffff16"},shadow:true,font:{uri:"",family:""},border:{left:false,top:false,bottom:true,right:false}});g.set("modern-light",{theme:"modern-light",dark:false,style:"modern",color:{primary:"#ffd110ff",primaryText:"#000000ff",background:"#ffffffff",text:"#000000ff",fieldBackground:"#00000000",fieldFocusBackground:"#00000000",fieldBorder:"#00000011"},shadow:true,font:{uri:"https://fonts.googleapis.com/css2?family=Open+Sans:wght@400;600&display=swap&subset=cyrillic",family:"Open Sans"},border:{left:false,top:false,bottom:true,right:false}});g.set("modern-dark",{theme:"modern-dark",dark:true,style:"modern",color:{primary:"#ffd110ff",primaryText:"#000000ff",background:"#282d30ff",text:"#ffffffff",fieldBackground:"#00000000",fieldFocusBackground:"#00000000",fieldBorder:"#ffffff11"},shadow:true,font:{uri:"https://fonts.googleapis.com/css2?family=Open+Sans:wght@400;600&display=swap&subset=cyrillic",family:"Open Sans"},border:{left:false,top:false,bottom:true,right:false}});g.set("classic-light",{theme:"classic-light",dark:false,style:"",color:{primary:"#000000ff",primaryText:"#ffffffff",background:"#ffffffff",text:"#000000ff",fieldBackground:"#00000011",fieldFocusBackground:"#0000000a",fieldBorder:"#00000011"},shadow:true,font:{uri:"https://fonts.googleapis.com/css2?family=PT+Serif:wght@400;700&display=swap&subset=cyrillic",family:"PT Serif"},border:{left:false,top:false,bottom:true,right:false}});g.set("classic-dark",{theme:"classic-dark",dark:true,style:"",color:{primary:"#ffffffff",primaryText:"#000000ff",background:"#000000ff",text:"#ffffffff",fieldBackground:"#ffffff11",fieldFocusBackground:"#ffffff0a",fieldBorder:"#ffffff11"},shadow:true,font:{uri:"https://fonts.googleapis.com/css2?family=PT+Serif:wght@400;700&display=swap&subset=cyrillic",family:"PT Serif"},border:{left:false,top:false,bottom:true,right:false}});g.set("fun-light",{theme:"fun-light",dark:false,style:"",color:{primary:"#f09b22ff",primaryText:"#000000ff",background:"#ffffffff",text:"#000000ff",fieldBackground:"#f09b2211",fieldFocusBackground:"#0000000a",fieldBorder:"#00000011"},shadow:true,font:{uri:"https://fonts.googleapis.com/css2?family=Pangolin&display=swap&subset=cyrillic",family:"Pangolin"},border:{left:false,top:false,bottom:true,right:false}});g.set("fun-dark",{theme:"fun-dark",dark:true,style:"",color:{primary:"#f09b22ff",primaryText:"#000000ff",background:"#221400ff",text:"#ffffffff",fieldBackground:"#f09b2211",fieldFocusBackground:"#ffffff0a",fieldBorder:"#f09b220a"},shadow:true,font:{uri:"https://fonts.googleapis.com/css2?family=Pangolin&display=swap&subset=cyrillic",family:"Pangolin"},border:{left:false,top:false,bottom:true,right:false}});g.set("pixel-light",{theme:"pixel-light",dark:true,style:"",color:{primary:"#00a74cff",primaryText:"#ffffffff",background:"#282d30ff",text:"#90ee90ff",fieldBackground:"#ffffff11",fieldFocusBackground:"#00000028",fieldBorder:"#ffffff16"},shadow:true,font:{uri:"https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap&subset=cyrillic",family:"Press Start 2P"},border:{left:false,top:false,bottom:true,right:false}});g.set("pixel-dark",u(u({},g.get("pixel-light")),{},{theme:"pixel-dark"}));function m(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);if(t)o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}));r.push.apply(r,o)}return r}function p(e){for(var t=1;t<arguments.length;t++){var r=arguments[t]!=null?arguments[t]:{};if(t%2){m(Object(r),true).forEach((function(t){babelHelpers.defineProperty(e,t,r[t])}))}else if(Object.getOwnPropertyDescriptors){Object.defineProperties(e,Object.getOwnPropertyDescriptors(r))}else{m(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}}return e}var F=function(e){babelHelpers.inherits(r,e);function r(e){var o;babelHelpers.classCallCheck(this,r);o=babelHelpers.possibleConstructorReturn(this,babelHelpers.getPrototypeOf(r).call(this));o.setEventNamespace("BX.Landing.FormStyleAdapter");o.options=p({},e);o.cache=new t.Cache.MemoryCache;o.onDebouncedFormChange=t.Runtime.debounce(o.onDebouncedFormChange,500);return o}babelHelpers.createClass(r,[{key:"setFormOptions",value:function e(t){this.cache.set("formOptions",p({},t))}},{key:"getFormOptions",value:function e(){return this.cache.get("formOptions")}},{key:"load",value:function e(){var r=this;if(t.Text.capitalize(n.Env.getInstance().getOptions().params.type)==="SMN"){this.setFormOptions({data:{design:t.Runtime.clone(this.getCrmForm().design)}});return Promise.resolve(this)}return t.Runtime.loadExtension("crm.form.client").then((function(e){var o=e.FormClient;if(o){return o.getInstance().getOptions(r.options.formId).then((function(e){r.setFormOptions(t.Runtime.merge(t.Runtime.clone(e),{data:{design:t.Runtime.clone(r.getCrmForm().design)}}));return r}))}return null}))}},{key:"getThemeField",value:function e(){var r=this;return this.cache.remember("themeField",(function(){var e=r.getFormOptions().data.design.theme;var o=d.PageObject.getRootWindow();return new o.BX.Landing.UI.Field.Dropdown({selector:"theme",title:i.Loc.getMessage("LANDING_FORM_STYLE_ADAPTER_THEME_FIELD_TITLE"),content:t.Type.isString(e)?e.split("-")[0]:"",onChange:r.onThemeChange.bind(r),items:[{name:i.Loc.getMessage("LANDING_FORM_STYLE_ADAPTER_THEME_FIELD_ITEM_BUSINESS"),value:"business"},{name:i.Loc.getMessage("LANDING_FORM_STYLE_ADAPTER_THEME_FIELD_ITEM_MODERN"),value:"modern"},{name:i.Loc.getMessage("LANDING_FORM_STYLE_ADAPTER_THEME_FIELD_ITEM_CLASSIC"),value:"classic"},{name:i.Loc.getMessage("LANDING_FORM_STYLE_ADAPTER_THEME_FIELD_ITEM_FUN"),value:"fun"},{name:i.Loc.getMessage("LANDING_FORM_STYLE_ADAPTER_THEME_FIELD_ITEM_PIXEL"),value:"pixel"}]})}))}},{key:"getDarkField",value:function e(){var r=this;return this.cache.remember("darkField",(function(){var e=r.getFormOptions().data.design.theme;var o=d.PageObject.getRootWindow();return new o.BX.Landing.UI.Field.Dropdown({selector:"dark",title:i.Loc.getMessage("LANDING_FORM_STYLE_ADAPTER_DARK_FIELD_TITLE"),content:t.Type.isString(e)?e.split("-")[1]:"",onChange:r.onThemeChange.bind(r),items:[{name:i.Loc.getMessage("LANDING_FORM_STYLE_ADAPTER_DARK_FIELD_ITEM_LIGHT"),value:"light"},{name:i.Loc.getMessage("LANDING_FORM_STYLE_ADAPTER_DARK_FIELD_ITEM_DARK"),value:"dark"}]})}))}},{key:"onThemeChange",value:function e(){var o=this.getStyleForm().serialize().theme;var a=g.get(o);if(a){if(t.Type.isPlainObject(a.color)){this.getPrimaryColorField().setValue({"--color":r.prepareColorFieldValue(a.color.primary)});this.getPrimaryTextColorField().setValue({"--color":r.prepareColorFieldValue(a.color.primaryText)});this.getBackgroundColorField().setValue({"--color":r.prepareColorFieldValue(a.color.background)});this.getTextColorField().setValue({"--color":r.prepareColorFieldValue(a.color.text)});this.getFieldBackgroundColorField().setValue({"--color":r.prepareColorFieldValue(a.color.fieldBackground)});this.getFieldFocusBackgroundColorField().setValue({"--color":r.prepareColorFieldValue(a.color.fieldFocusBackground)});this.getFieldBorderColorField().setValue({"--color":r.prepareColorFieldValue(a.color.fieldBorder)})}this.getStyleField().setValue(a.style);if(t.Type.isBoolean(a.shadow)){this.getShadowField().setValue(a.shadow)}if(t.Type.isPlainObject(a.font)){var l=p({},a.font);if(!t.Type.isStringFilled(l.family)){l.family=i.Loc.getMessage("LANDING_FORM_STYLE_ADAPTER_FONT_DEFAULT")}this.getFontField().setValue(l)}if(t.Type.isPlainObject(a.border)){var n=Object.entries(a.border).reduce((function(e,t){var r=babelHelpers.slicedToArray(t,2),o=r[0],i=r[1];if(i){e.push(o)}return e}),[]);this.getBorderField().setValue(n)}}}},{key:"getShadowField",value:function e(){var t=this;return this.cache.remember("shadow",(function(){var e=d.PageObject.getRootWindow();return new e.BX.Landing.UI.Field.Dropdown({selector:"shadow",title:i.Loc.getMessage("LANDING_FORM_STYLE_ADAPTER_SHADOW"),content:t.getFormOptions().data.design.shadow,items:[{name:i.Loc.getMessage("LANDING_FORM_STYLE_ADAPTER_SHADOW_USE"),value:true},{name:i.Loc.getMessage("LANDING_FORM_STYLE_ADAPTER_SHADOW_NOT_USE"),value:false}]})}))}},{key:"getStyleField",value:function e(){var t=this;return this.cache.remember("styleField",(function(){var e=d.PageObject.getRootWindow();return new e.BX.Landing.UI.Field.Dropdown({selector:"style",title:i.Loc.getMessage("LANDING_FORM_STYLE_ADAPTER_STYLE_FIELD_TITLE"),content:t.getFormOptions().data.design.style,items:[{name:i.Loc.getMessage("LANDING_FORM_STYLE_ADAPTER_STYLE_FIELD_ITEM_STANDARD"),value:""},{name:i.Loc.getMessage("LANDING_FORM_STYLE_ADAPTER_STYLE_FIELD_ITEM_MODERN"),value:"modern"}]})}))}},{key:"getPrimaryColorField",value:function e(){var o=this;return this.cache.remember("primaryColorField",(function(){var e=d.PageObject.getRootWindow();var a=new e.BX.Landing.UI.Field.ColorField({selector:"primary",title:i.Loc.getMessage("LANDING_FORM_STYLE_ADAPTER_PRIMARY_COLOR"),subtype:"color"});t.Dom.hide(a.layout.querySelector(".landing-ui-field-color-primary"));a.setValue({"--color":r.prepareColorFieldValue(o.getFormOptions().data.design.color.primary)});return a}))}},{key:"getPrimaryTextColorField",value:function e(){var o=this;return this.cache.remember("primaryTextColorField",(function(){var e=d.PageObject.getRootWindow();var a=new e.BX.Landing.UI.Field.ColorField({selector:"primaryText",title:i.Loc.getMessage("LANDING_FORM_STYLE_ADAPTER_PRIMARY_TEXT_COLOR"),subtype:"color"});t.Dom.hide(a.layout.querySelector(".landing-ui-field-color-primary"));a.setValue({"--color":r.prepareColorFieldValue(o.getFormOptions().data.design.color.primaryText)});return a}))}},{key:"getBackgroundColorField",value:function e(){var o=this;return this.cache.remember("backgroundColorField",(function(){var e=d.PageObject.getRootWindow();var a=new e.BX.Landing.UI.Field.ColorField({selector:"background",title:i.Loc.getMessage("LANDING_FORM_STYLE_ADAPTER_BACKGROUND_COLOR"),subtype:"color"});t.Dom.hide(a.layout.querySelector(".landing-ui-field-color-primary"));a.setValue({"--color":r.prepareColorFieldValue(o.getFormOptions().data.design.color.background)});return a}))}},{key:"getTextColorField",value:function e(){var o=this;return this.cache.remember("textColorField",(function(){var e=d.PageObject.getRootWindow();var a=new e.BX.Landing.UI.Field.ColorField({selector:"text",title:i.Loc.getMessage("LANDING_FORM_STYLE_ADAPTER_TEXT_COLOR"),subtype:"color"});t.Dom.hide(a.layout.querySelector(".landing-ui-field-color-primary"));a.setValue({"--color":r.prepareColorFieldValue(o.getFormOptions().data.design.color.text)});return a}))}},{key:"getFieldBackgroundColorField",value:function e(){var o=this;return this.cache.remember("fieldBackgroundColorField",(function(){var e=d.PageObject.getRootWindow();var a=new e.BX.Landing.UI.Field.ColorField({selector:"fieldBackground",title:i.Loc.getMessage("LANDING_FORM_STYLE_ADAPTER_FIELD_BACKGROUND_COLOR"),subtype:"color"});t.Dom.hide(a.layout.querySelector(".landing-ui-field-color-primary"));a.setValue({"--color":r.prepareColorFieldValue(o.getFormOptions().data.design.color.fieldBackground)});return a}))}},{key:"getFieldFocusBackgroundColorField",value:function e(){var o=this;return this.cache.remember("fieldFocusBackgroundColorField",(function(){var e=d.PageObject.getRootWindow();var a=new e.BX.Landing.UI.Field.ColorField({selector:"fieldFocusBackground",title:i.Loc.getMessage("LANDING_FORM_STYLE_ADAPTER_FIELD_FOCUS_BACKGROUND_COLOR"),value:o.getFormOptions().data.design.color.fieldFocusBackground,subtype:"color"});t.Dom.hide(a.layout.querySelector(".landing-ui-field-color-primary"));a.setValue({"--color":r.prepareColorFieldValue(o.getFormOptions().data.design.color.fieldFocusBackground)});return a}))}},{key:"getFieldBorderColorField",value:function e(){var o=this;return this.cache.remember("fieldBorderColorField",(function(){var e=d.PageObject.getRootWindow();var a=new e.BX.Landing.UI.Field.ColorField({selector:"fieldBorder",title:i.Loc.getMessage("LANDING_FORM_STYLE_ADAPTER_FIELD_BORDER_COLOR"),value:o.getFormOptions().data.design.color.fieldBorder,subtype:"color"});t.Dom.hide(a.layout.querySelector(".landing-ui-field-color-primary"));a.setValue({"--color":r.prepareColorFieldValue(o.getFormOptions().data.design.color.fieldBorder)});return a}))}},{key:"getFontField",value:function e(){var r=this;return this.cache.remember("fontField",(function(){var e=p({},r.getFormOptions().data.design.font);if(!t.Type.isStringFilled(e.family)){e.family=i.Loc.getMessage("LANDING_FORM_STYLE_ADAPTER_FONT_DEFAULT")}return new BX.Landing.UI.Field.Font({selector:"font",title:i.Loc.getMessage("LANDING_FORM_STYLE_ADAPTER_FONT"),headlessMode:true,value:e})}))}},{key:"getBorderField",value:function e(){var t=this;return this.cache.remember("borderField",(function(){return new BX.Landing.UI.Field.Checkbox({selector:"border",title:i.Loc.getMessage("LANDING_FORM_STYLE_ADAPTER_BORDER"),value:function(){var e=t.getFormOptions().data.design.border;return Object.entries(e).reduce((function(e,t){var r=babelHelpers.slicedToArray(t,2),o=r[0],i=r[1];if(i){e.push(o)}return e}),[])}(),items:[{name:i.Loc.getMessage("LANDING_FORM_STYLE_ADAPTER_BORDER_LEFT"),value:"left"},{name:i.Loc.getMessage("LANDING_FORM_STYLE_ADAPTER_BORDER_RIGHT"),value:"right"},{name:i.Loc.getMessage("LANDING_FORM_STYLE_ADAPTER_BORDER_TOP"),value:"top"},{name:i.Loc.getMessage("LANDING_FORM_STYLE_ADAPTER_BORDER_BOTTOM"),value:"bottom"}]})}))}},{key:"getStyleForm",value:function e(){var a=this;return this.cache.remember("styleForm",(function(){return new o.StyleForm({title:i.Loc.getMessage("LANDING_FORM_STYLE_ADAPTER_FORM_TITLE"),fields:[a.getThemeField(),a.getDarkField(),a.getStyleField(),a.getShadowField(),a.getPrimaryColorField(),a.getPrimaryTextColorField(),a.getBackgroundColorField(),a.getTextColorField(),a.getFieldBackgroundColorField(),a.getFieldFocusBackgroundColorField(),a.getFieldBorderColorField(),a.getFontField(),a.getBorderField()],onChange:t.Runtime.throttle(a.onFormChange.bind(a),16),serializeModifier:function e(o){o.theme="".concat(o.theme,"-").concat(o.dark);o.dark=o.dark==="dark";o.shadow=t.Text.toBoolean(o.shadow);o.color={primary:r.convertColorFieldValueToHexa(o.primary.getHex(),o.primary.getOpacity()),primaryText:r.convertColorFieldValueToHexa(o.primaryText.getHex(),o.primaryText.getOpacity()),text:r.convertColorFieldValueToHexa(o.text.getHex(),o.text.getOpacity()),background:r.convertColorFieldValueToHexa(o.background.getHex(),o.background.getOpacity()),fieldBackground:r.convertColorFieldValueToHexa(o.fieldBackground.getHex(),o.fieldBackground.getOpacity()),fieldFocusBackground:r.convertColorFieldValueToHexa(o.fieldFocusBackground.getHex(),o.fieldFocusBackground.getOpacity()),fieldBorder:r.convertColorFieldValueToHexa(o.fieldBorder.getHex(),o.fieldBorder.getOpacity())};o.border={left:o.border.includes("left"),right:o.border.includes("right"),top:o.border.includes("top"),bottom:o.border.includes("bottom")};if(o.font.family===i.Loc.getMessage("LANDING_FORM_STYLE_ADAPTER_FONT_DEFAULT")){o.font.family="";o.font.uri=""}delete o.primary;delete o.primaryText;delete o.text;delete o.background;delete o.fieldBackground;delete o.fieldFocusBackground;delete o.fieldBorder;return o}})}))}},{key:"getCrmForm",value:function e(){var r=t.Reflection.getClass("b24form.App");if(r){if(this.options.instanceId){return r.get(this.options.instanceId)}return r.list()[0]}return null}},{key:"onFormChange",value:function e(r){var o=this.getFormOptions();var i={data:{design:r.getTarget().serialize()}};var a=t.Runtime.merge(o,i);this.setFormOptions(a);this.getCrmForm().design.adjust(a.data.design);var l=f.FormSettingsPanel.getInstance();if(l.isShown()){var n=l.getInitialFormOptions();var s=l.getFormOptions();n.data.design=a.data.design;l.setInitialFormOptions(n);s.data.design=a.data.design;l.setFormOptions(s)}this.onDebouncedFormChange()}},{key:"isCrmFormPage",value:function e(){return n.Env.getInstance().getOptions().specialType==="crm_forms"}},{key:"saveFormDesign",value:function e(){var r=this;return t.Runtime.loadExtension("crm.form.client").then((function(e){var t=e.FormClient;if(t){var o=t.getInstance();var i=r.getFormOptions();o.resetCache(i.id);return o.saveOptions(i)}return null}))}},{key:"saveBlockDesign",value:function e(){var r=this;var o=this.options.currentBlock;var i=this.getFormOptions().data.design;var a=o.node.querySelector(".bitrix24forms");t.Dom.attr(a,{"data-b24form-design":i,"data-b24form-use-style":"Y"});t.Runtime.loadExtension("crm.form.client").then((function(e){var t=e.FormClient;if(t){var o=t.getInstance();var i=r.getFormOptions();o.resetCache(i.id)}}));l.Backend.getInstance().action("Landing\\Block::updateNodes",{block:o.id,data:{".bitrix24forms":{attrs:{"data-b24form-design":JSON.stringify(i),"data-b24form-use-style":"Y"}}},lid:o.lid,siteId:o.siteId},{code:o.manifest.code})}},{key:"onDebouncedFormChange",value:function e(){var r=this;if(this.isCrmFormPage()){t.Runtime.loadExtension("landing.ui.panel.formsettingspanel").then((function(e){var t=e.FormSettingsPanel;var o=t.getInstance();o.setCurrentBlock(r.options.currentBlock);void r.saveFormDesign();if(o.useBlockDesign()){o.disableUseBlockDesign()}}))}else{this.saveBlockDesign()}}}],[{key:"prepareColorFieldValue",value:function e(t){return a.ColorPickerField.toRgba.apply(a.ColorPickerField,babelHelpers.toConsumableArray(a.ColorPickerField.parseHex(t)))}},{key:"convertColorFieldValueToHexa",value:function e(r){var o=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;var i=a.ColorPickerField.parseHex(r);if(!t.Type.isNil(o)){i[3]=o}return a.ColorPickerField.toHex.apply(a.ColorPickerField,babelHelpers.toConsumableArray(i))}}]);return r}(r.EventEmitter);e.FormStyleAdapter=F})(this.BX.Landing=this.BX.Landing||{},BX,BX.Event,BX.Landing.UI.Form,BX.Landing,BX.Landing.Ui.Field,BX.Landing,BX.Landing,BX.Landing.UI.Field,BX.Landing,BX.Landing.UI.Panel);
//# sourceMappingURL=formstyleadapter.bundle.map.js